home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility2 / wine02bx.zip / INFO / ELISP.10 < prev    next >
Text File  |  1993-03-28  |  51KB  |  1,278 lines

  1. Info file elisp, produced by Makeinfo, -*- Text -*- from input file
  2. elisp.texi.
  3.  
  4.    This file documents GNU Emacs Lisp.
  5.  
  6.    This is edition 1.03 of the GNU Emacs Lisp Reference Manual,   for
  7. Emacs Version 18.
  8.  
  9.    Published by the Free Software Foundation, 675 Massachusetts
  10. Avenue,  Cambridge, MA 02139 USA
  11.  
  12.    Copyright (C) 1990 Free Software Foundation, Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of
  15. this manual provided the copyright notice and this permission notice
  16. are preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided that
  20. the entire resulting derived work is distributed under the terms of a
  21. permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Foundation.
  27.  
  28.  
  29. 
  30. File: elisp,  Node: Output Functions,  Prev: Output Streams,  Up: Streams
  31.  
  32. Output Functions
  33. ----------------
  34.  
  35.    This section describes the Lisp functions and variables that
  36. pertain to printing.
  37.  
  38.    Some of the Emacs printing functions add quoting characters to the
  39. output when necessary so that it can be read properly.  The quoting
  40. characters used are `\' and `"'; they are used to distinguish strings
  41. from symbols, and to prevent punctuation characters in strings and
  42. symbols from being taken as delimiters.  *Note Printed
  43. Representation::, for full details.  You specify quoting or no
  44. quoting by the choice of printing function.
  45.  
  46.    If the text is to be read back into Lisp, then it is best to print
  47. with quoting characters to avoid ambiguity.  Likewise, if the purpose
  48. is to describe a Lisp object clearly for a Lisp programmer.  However,
  49. if the purpose of the output is to look nice for humans, then it is
  50. better to print without quoting.
  51.  
  52.    In the functions below, STREAM stands for an output stream.  (See
  53. the previous section for a description of output streams.)  If STREAM
  54. is `nil' or omitted, it defaults to the value of `standard-output'.
  55.  
  56.  * Function: print OBJECT &optional STREAM
  57.      The `print' is a convenient way of printing.  It outputs the
  58.      printed representation of OBJECT to STREAM, printing in addition
  59.      one newline before OBJECT and another after it.  Quoting
  60.      characters are used.  `print' returns OBJECT.  For example:
  61.  
  62.           (progn (print 'The\ cat\ in)
  63.                  (print "the hat")
  64.                  (print " came back"))
  65.                -| 
  66.                -| The\ cat\ in
  67.                -| 
  68.                -| "the hat"
  69.                -| 
  70.                -| " came back"
  71.                -| 
  72.                => " came back"
  73.  
  74.  * Function: prin1 OBJECT &optional STREAM
  75.      This function outputs the printed representation of OBJECT to
  76.      STREAM.  It does not print any spaces or newlines to separate
  77.      output as `print' does, but it does use quoting characters just
  78.      like `print'.  It returns OBJECT.
  79.  
  80.           (progn (prin1 'The\ cat\ in) 
  81.                  (prin1 "the hat") 
  82.                  (prin1 " came back"))
  83.                -| The\ cat\ in"the hat"" came back"
  84.                => " came back"
  85.  
  86.  * Function: prin1-to-string OBJECT
  87.      This function returns a string containing the text that `prin1'
  88.      would have printed for the same argument.
  89.  
  90.           (prin1-to-string 'foo)
  91.                => "foo"
  92.           (prin1-to-string (mark-marker))
  93.                => "#<marker at 2773 in strings.texi>"
  94.  
  95.      See `format', in *Note String Conversion::, for other ways to
  96.      obtain the printed representation of a Lisp object as a string.
  97.  
  98.  * Function: princ OBJECT &optional STREAM
  99.      This function outputs the printed representation of OBJECT to
  100.      STREAM.  It returns OBJECT.
  101.  
  102.      This function is intended to produce output that is readable by
  103.      people, not by `read', so quoting characters are not used and
  104.      double-quotes are not printed around the contents of strings. 
  105.      It does not add any spacing between calls.
  106.  
  107.           (progn
  108.             (princ 'The\ cat)
  109.             (princ " in the \"hat\""))
  110.                -| The cat in the "hat"
  111.                => " in the \"hat\""
  112.  
  113.  * Function: terpri &optional STREAM
  114.      This function outputs a newline to STREAM.  The name stands for
  115.      "terminate print".
  116.  
  117.  * Variable: standard-output
  118.      The value of this variable is the default output stream, used
  119.      when the STREAM argument is omitted or `nil'.
  120.  
  121.  * Variable: print-escape-newlines
  122.      If this variable is non-`nil', then newline characters in
  123.      strings are printed as `\n'.  Normally they are printed as
  124.      actual newlines.
  125.  
  126.      This variable affects the print functions `prin1' and `print';
  127.      it does not affect `princ' in Emacs 18, but this may be changed.
  128.      Here is an example using `prin1':
  129.  
  130.           (prin1 "a\nb")
  131.                -| "a
  132.                -| b"
  133.                => "a
  134.                => b"
  135.           
  136.           (let ((print-escape-newlines t))
  137.             (prin1 "a\nb"))
  138.                -| "a\nb"
  139.                => "a
  140.                => b"
  141.  
  142.      In the second expression, the local binding of
  143.      `print-escape-newlines' is in effect during the call to `prin1',
  144.      but not during the printing of the result.
  145.  
  146.  * Variable: print-length
  147.      The value of this variable is the maximum number of elements of
  148.      a list that will be printed.  If the list being printed has more
  149.      than this many elements, then it is abbreviated with an ellipsis.
  150.  
  151.      If the value is `nil' (the default), then there is no limit.
  152.  
  153.           (setq print-length 2)
  154.                => 2
  155.           (print '(1 2 3 4 5))
  156.                -| (1 2 ...)
  157.                => (1 2 ...)
  158.  
  159.  * Function: write-char CHARACTER &optional STREAM
  160.      This function outputs CHARACTER to STREAM.  It returns CHARACTER.
  161.  
  162.  
  163. 
  164. File: elisp,  Node: Minibuffers,  Next: Command Loop,  Prev: Streams,  Up: Top
  165.  
  166. Minibuffers
  167. ***********
  168.  
  169.    A "minibuffer" is a special buffer used by Emacs commands to read
  170. arguments more complicated than the single numeric prefix argument. 
  171. These arguments include file names, buffer names, and command names
  172. (as in `M-x').  The minibuffer is displayed on the bottom line of the
  173. screen, in the same place as the echo area, but only while it is in
  174. use for reading an argument.
  175.  
  176. * Menu:
  177.  
  178. * Intro to Minibuffers::      Basic information about minibuffers.
  179. * Text from Minibuffer::      How to read a straight text string.
  180. * Object from Minibuffer::    How to read a Lisp object or expression.
  181. * Completion::                How to invoke and customize completion.
  182. * Yes-or-No Queries::         Asking a question with a simple answer.
  183. * Minibuffer Misc::           Various customization hooks and variables.
  184.  
  185.  
  186. 
  187. File: elisp,  Node: Intro to Minibuffers,  Next: Text from Minibuffer,  Prev: Minibuffers,  Up: Minibuffers
  188.  
  189. Introduction to Minibuffers
  190. ===========================
  191.  
  192.    In most ways, a minibuffer is a normal Emacs buffer.  Most
  193. operations *within* a buffer, such as editing commands, work normally
  194. in a minibuffer.  However, many operations for managing buffers do
  195. not apply to minibuffers.  The name of a minibuffer always has the
  196. form ` *Minibuf-NUMBER', and it cannot be changed.  There is a
  197. special window used only for minibuffers, and minibuffers cannot be
  198. displayed in any other window.  This window is normally the single
  199. line at the bottom of the screen; it can be resized temporarily with
  200. the window sizing commands, but reverts to its normal size when the
  201. minibuffer is exited.
  202.  
  203.    A "recursive minibuffer" may be created when there is an active
  204. minibuffer and a command is invoked that requires input from a
  205. minibuffer.  The first minibuffer is named ` *Minibuf-0*'.  Recursive
  206. minibuffers are named by incrementing the number at the end of the
  207. name.  (The names begin with a space so that they won't show up in
  208. normal buffer lists.)  Of several recursive minibuffers, the
  209. innermost (or most recently entered) is the active minibuffer, and is
  210. the only one that is displayed in a window.  We usually call this
  211. "the" minibuffer.  Recursive minibuffers may be allowed or disallowed
  212. by setting the variable `enable-recursive-minibuffers'.
  213.  
  214.    Like other buffers, a minibuffer may use any of several local
  215. keymaps (*note Keymaps::.); these contain various exit commands and
  216. in some cases completion commands.  *Note Completion::.
  217.  
  218.    * `minibuffer-local-map' is for ordinary input (no completion).
  219.  
  220.    * `minibuffer-local-ns-map' is similar, except that SPC exits just
  221.      like RET.  This is used mainly for Mocklisp compatibility.
  222.  
  223.    * `minibuffer-local-completion-map' is for permissive completion.
  224.  
  225.    * `minibuffer-local-must-match-map' is for strict completion and
  226.      for cautious completion.
  227.  
  228.    * `repeat-complex-command-map' is for use in `C-x ESC'.
  229.  
  230.  
  231. 
  232. File: elisp,  Node: Text from Minibuffer,  Next: Object from Minibuffer,  Prev: Intro to Minibuffers,  Up: Minibuffers
  233.  
  234. Reading Text Strings with the Minibuffer
  235. ========================================
  236.  
  237.    The minibuffer is usually used to read text which is returned as a
  238. string, but can also be used to read a Lisp object in textual form. 
  239. The most basic primitive for minibuffer input is
  240. `read-from-minibuffer'.
  241.  
  242.  * Function: read-from-minibuffer PROMPT-STRING &optional INITIAL
  243.           KEYMAP READ
  244.      This function is the most general way to get input through the
  245.      minibuffer.  By default, it accepts arbitrary text and returns
  246.      it as a string; however, if READ is non-`nil', then it uses
  247.      `read' to convert the text into a Lisp object (*note Input
  248.      Functions::.).
  249.  
  250.      The first thing this function does is to activate a minibuffer
  251.      and  display it with  PROMPT-STRING as the prompt.  This value
  252.      must be a string.
  253.  
  254.      Then, if INITIAL is non-`nil', it must be a string; its contents
  255.      are inserted into the minibuffer as initial contents.  The text
  256.      thus inserted is treated as if the user had inserted it; the
  257.      user can alter it with Emacs editing commands.
  258.  
  259.      If KEYMAP is non-`nil', that keymap is the local keymap to use
  260.      while reading.  If KEYMAP is omitted or `nil', the value of
  261.      `minibuffer-local-map' is used as the keymap.  Specifying a
  262.      keymap is the most important way to customize minibuffer input
  263.      for various applications including completion.
  264.  
  265.      When the user types a command to exit the minibuffer, the
  266.      current minibuffer contents are usually made into a string which
  267.      is the value of `read-from-minibuffer'.  However, if READ is
  268.      non-`nil', Emacs converts the result to a Lisp object and
  269.      `read-from-minibuffer' returns that object, unevaluated.
  270.  
  271.      Suppose, for example, you are writing a search command and want
  272.      to record the last search string and provide it as a default for
  273.      the next search.  Suppose that the previous search string is
  274.      stored in the variable `last-search-string'.  Here is how you
  275.      can read a search string while providing the previous string as
  276.      initial input to be edited:
  277.  
  278.           (read-from-minibuffer "Find string: " last-search-string)
  279.  
  280.      Assuming the value of `last-search-string' is `No', and the user
  281.      wants to search for `Nope', the interaction looks like this:
  282.  
  283.           (setq last-search-string "No")
  284.           
  285.           (read-from-minibuffer "Find string: " last-search-string)
  286.           ---------- Buffer: Minibuffer ----------
  287.           Find string: No-!-
  288.           ---------- Buffer: Minibuffer ----------
  289.           ;; The user now types `pe RET':
  290.                => "Nope"
  291.  
  292.  * Function: read-string PROMPT &optional INITIAL
  293.      This function reads a string from the minibuffer and returns it.
  294.      The arguments PROMPT and INITIAL are used as in
  295.      `read-from-minibuffer'.
  296.  
  297.      This function is a simplified interface to `read-from-minibuffer':
  298.  
  299.           (read-string PROMPT INITIAL)
  300.           ==
  301.           (read-from-minibuffer PROMPT INITIAL nil nil)
  302.  
  303.  * Variable: minibuffer-local-map
  304.      This is the default local keymap for reading from the
  305.      minibuffer.  It is the keymap used by the minibuffer for local
  306.      bindings in the function `read-string'.  By default, it makes
  307.      the following bindings:
  308.  
  309.     LFD
  310.           `exit-minibuffer'
  311.  
  312.     RET
  313.           `exit-minibuffer'
  314.  
  315.     `C-g'
  316.           `abort-recursive-edit'
  317.  
  318.  * Function: read-no-blanks-input PROMPT INITIAL
  319.      This function reads a string from the minibuffer, but does not
  320.      allow whitespace characters as part of the input: instead, those
  321.      characters terminate the input.  The arguments PROMPT and
  322.      INITIAL are used as in `read-from-minibuffer'.
  323.  
  324.      This function is a simplified interface to
  325.      `read-from-minibuffer', and passes the value of
  326.      `minibuffer-local-ns-map' as the KEYMAP argument for that
  327.      function.  Since the keymap `minibuffer-local-ns-map' does not
  328.      rebind `C-q', it *is* possible to put a space into the string,
  329.      by quoting it.
  330.  
  331.           (read-no-blanks-input PROMPT INITIAL)
  332.           ==
  333.           (read-from-minibuffer PROMPT INITIAL minibuffer-local-ns-map)
  334.  
  335.  * Variable: minibuffer-local-ns-map
  336.      This built-in variable is the keymap used as the minibuffer
  337.      local keymap in the function `read-no-blanks-input'.  By
  338.      default, it makes the following bindings:
  339.  
  340.     `LFD'
  341.           `exit-minibuffer'
  342.  
  343.     `SPC'
  344.           `exit-minibuffer'
  345.  
  346.     `TAB'
  347.           `exit-minibuffer'
  348.  
  349.     `RET'
  350.           `exit-minibuffer'
  351.  
  352.     `C-g'
  353.           `abort-recursive-edit'
  354.  
  355.     `?'
  356.           `self-insert-and-exit'
  357.  
  358.  
  359. 
  360. File: elisp,  Node: Object from Minibuffer,  Next: Completion,  Prev: Text from Minibuffer,  Up: Minibuffers
  361.  
  362. Reading Lisp Objects with the Minibuffer
  363. ========================================
  364.  
  365.    This section describes functions for reading Lisp objects with the
  366. minibuffer.
  367.  
  368.  * Function: read-minibuffer PROMPT &optional INITIAL
  369.      This function reads a Lisp object in the minibuffer and returns
  370.      it, unevaluated.  The arguments PROMPT and INITIAL are used as
  371.      in `read-from-minibuffer'; in particular, INITIAL must be a
  372.      string or `nil'.
  373.  
  374.      This function is a simplified interface to `read-from-minibuffer':
  375.  
  376.           (read-minibuffer PROMPT INITIAL)
  377.           ==
  378.           (read-from-minibuffer PROMPT INITIAL nil t)
  379.  
  380.      Here is an example in which we supply the string `"(testing)"'
  381.      as initial input:
  382.  
  383.           (read-minibuffer "Enter an expression: " (format "%s" '(testing)))
  384.           
  385.           ;;  Here is how the minibuffer is displayed:
  386.           
  387.           ---------- Buffer: Minibuffer ----------
  388.           Enter an expression: (testing)-!-
  389.           ---------- Buffer: Minibuffer ----------
  390.  
  391.      The user can type RET immediately to use the initial input as a
  392.      default, or can edit the input.
  393.  
  394.  * Function: eval-minibuffer PROMPT &optional INITIAL
  395.      This function reads a Lisp expression in the minibuffer,
  396.      evaluates it, then returns the result.  The arguments PROMPT and
  397.      INITIAL are used as in `read-from-minibuffer'.
  398.  
  399.      This function simply evaluates the result of a call to
  400.      `read-minibuffer':
  401.  
  402.           (eval-minibuffer PROMPT INITIAL)
  403.           ==
  404.           (eval (read-minibuffer PROMPT INITIAL))
  405.  
  406.  * Function: edit-and-eval-command PROMPT FORM
  407.      This function reads a Lisp expression in the minibuffer, and
  408.      then evaluates it.  The difference between this command and
  409.      `eval-minibuffer' is that here the initial FORM is not optional
  410.      and it is treated as a Lisp object to be converted to printed
  411.      representation rather than as a string of text.  It is printed
  412.      with `prin1', so if it is a string, double-quote characters
  413.      (`"') will appear in the initial text.  *Note Output Functions::.
  414.  
  415.      The first thing `edit-and-eval-command' does is to activate the
  416.      minibuffer with PROMPT as the prompt.  The printed
  417.      representation of FORM is then inserted in the minibuffer, and
  418.      the user is allowed to edit.  When the user exits the
  419.      minibuffer, the edited text is read with `read' and then
  420.      evaluated.  The resulting value becomes the value of
  421.      `edit-and-eval-command'.
  422.  
  423.      In the following example, we offer the user an expression with
  424.      initial text which is a valid form already:
  425.  
  426.           (edit-and-eval-command "Please edit: " '(forward-word 1))
  427.           
  428.           ;; After evaluating the preceding expression, 
  429.           ;; the following appears in the minibuffer:
  430.           
  431.           ---------- Buffer: Minibuffer ----------
  432.           Please edit: (forward-word 1)-!-
  433.           ---------- Buffer: Minibuffer ----------
  434.  
  435.      Typing RET right away would exit the minibuffer and evaluate the
  436.      expression, thus moving point forward one word. 
  437.      `edit-and-eval-command' returns `nil' in this example.
  438.  
  439.  
  440. 
  441. File: elisp,  Node: Completion,  Next: Yes-or-No Queries,  Prev: Object from Minibuffer,  Up: Minibuffers
  442.  
  443. Completion
  444. ==========
  445.  
  446.    "Completion" is a feature that fills in the rest of a name
  447. starting from an abbreviation for it.  Completion works by comparing
  448. the user's input against a list of valid names and determining how
  449. much of the name is determined uniquely by what the user has typed.
  450.  
  451.    For example, when you type `C-x b' (`switch-to-buffer') and then
  452. type the first few letters of the name of the buffer to which you
  453. wish to switch, and then type TAB (`minibuffer-complete'), Emacs
  454. extends the name as far as it can.  Standard Emacs commands offer
  455. completion for names of symbols, files, buffers, and processes; with
  456. the functions in this section, you can implement completion for other
  457. kinds of names.
  458.  
  459.    The `try-completion' function is the basic primitive for
  460. completion: it returns the longest determined completion of a given
  461. initial string, with a given set of strings to match against.
  462.  
  463.    The function `completing-read' provides a higher-level interface
  464. for completion.  A call to `completing-read' specifies how to
  465. determine the list of valid names.  The function then activates the
  466. minibuffer with a local keymap that binds a few keys to commands
  467. useful for completion.  Other functions provide convenient simple
  468. interfaces for reading certain kinds of names with completion.
  469.  
  470. * Menu:
  471.  
  472. * Basic Completion::       Low-level functions for completing strings.
  473.                              (These are too low level to use the minibuffer.)
  474. * Programmed Completion::  Finding the completions for a given file name.
  475. * Minibuffer Completion::  Invoking the minibuffer with completion.
  476. * Completion Commands::    Minibuffer commands that do completion.
  477. * High-Level Completion::  Convenient special cases of completion
  478.                              (reading buffer name, file name, etc.)
  479. * Reading File Names::     Using completion to read file names.
  480. * Lisp Symbol Completion:: Completing the name of a symbol.
  481.  
  482.  
  483. 
  484. File: elisp,  Node: Basic Completion,  Next: Programmed Completion,  Prev: Completion,  Up: Completion
  485.  
  486. Basic Completion Functions
  487. --------------------------
  488.  
  489.  * Function: try-completion STRING ALIST-OR-OBARRAY &optional PREDICATE
  490.      This function returns the longest common substring of all
  491.      possible completions of STRING in ALIST-OR-OBARRAY.
  492.  
  493.      If ALIST-OR-OBARRAY is an association list (*note Association
  494.      Lists::.), the CAR of each cons cell in it is compared against
  495.      STRING; if the beginning of the CAR equals STRING, the cons cell
  496.      matches.  If no cons cells match, `try-completion' returns
  497.      `nil'.  If only one cons cell matches, and the match is exact,
  498.      then `try-completion' returns `t'.  Otherwise, all matching
  499.      strings are compared, and the longest initial sequence common to
  500.      them is returned as a string.
  501.  
  502.      If ALIST-OR-OBARRAY is an obarray (*note Creating Symbols::.),
  503.      the names of all symbols in the obarray form the space of
  504.      possible names.  They are tested and used just like the CARs of
  505.      the elements of an association list.  (The global variable
  506.      `obarray' holds an obarray containing the names of all interned
  507.      Lisp symbols.)
  508.  
  509.      If the argument PREDICATE is non-`nil', then it must be a
  510.      function of one argument.  It is used to test each possible
  511.      match, and the match is accepted only if PREDICATE returns
  512.      non-`nil'.  The argument given to PREDICATE is either a cons
  513.      cell from the alist (the CAR of which is a string) or else it is
  514.      a symbol (*not* a symbol name) from the obarray.
  515.  
  516.      It is also possible to use a function as ALIST-OR-OBARRAY.  Then
  517.      the function is solely responsible for performing completion;
  518.      `try-completion' returns whatever this function returns.  The
  519.      function is called with three arguments: STRING, PREDICATE and
  520.      `nil'.  (The reason for the third argument is so that the same
  521.      function can be used in `all-completions' and do the appropriate
  522.      thing in either case.)  *Note Programmed Completion::.
  523.  
  524.      In the first of the following examples, the string `foo' is
  525.      matched by three of the alist CARs.  All of the matches begin
  526.      with the characters `fooba', so that is the result.  In the
  527.      second example, there is only one possible match, and it is
  528.      exact, so the value is `t'.
  529.  
  530.           (try-completion "foo"
  531.                '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)))
  532.                => "fooba"
  533.           
  534.           (try-completion "foo" '(("barfoo" 2) ("foo" 3)))
  535.                => t
  536.  
  537.      In the following example, numerous symbols begin with the
  538.      characters `forw', and all of them begin with the word
  539.      `forward'.  In most of the symbols, this is followed with a `-',
  540.      but not in all, so no more than `forward' can be completed.
  541.  
  542.           (try-completion "forw" obarray)
  543.                => "forward"
  544.  
  545.      Finally, in the following example, only two of the three
  546.      possible matches pass the predicate `test' (the string `foobaz'
  547.      is too short).  Both of those begin with the string `foobar'.
  548.  
  549.           (defun test (s) 
  550.             (> (length (car s)) 6))
  551.                => test
  552.           (try-completion "foo"
  553.                '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)) 
  554.                'test)
  555.                => "foobar"
  556.  
  557.  * Function: all-completions STRING ALIST-OR-OBARRAY &optional
  558.           PREDICATE
  559.      This function returns a list of all possible completions,
  560.      instead of the longest substring they share.  The parameters to
  561.      this function are the same as to `try-completion'.
  562.  
  563.      If ALIST-OR-OBARRAY is a function, it is called with three
  564.      arguments: STRING, PREDICATE and `t', and `all-completions'
  565.      returns whatever the function returns.  *Note Programmed
  566.      Completion::.
  567.  
  568.      Here is an example, using the same function `test' used in the
  569.      example for `try-completion':
  570.  
  571.           (defun test (s) 
  572.             (> (length (car s)) 6))
  573.                => test
  574.           
  575.           (all-completions  "foo"
  576.                '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
  577.                (function test))
  578.                => ("foobar1" "foobar2")
  579.  
  580.  * Variable: completion-ignore-case
  581.      If the value of this variable is  non-`nil', Emacs does not
  582.      consider case significant in completion.
  583.  
  584.    The two functions `try-completion' and `all-completions' have
  585. nothing in themselves to do with minibuffers.  However, completion is
  586. most often used there, which is why it is described in this chapter.
  587.  
  588.  
  589. 
  590. File: elisp,  Node: Programmed Completion,  Next: Minibuffer Completion,  Prev: Basic Completion,  Up: Completion
  591.  
  592. Programmed Completion
  593. ---------------------
  594.  
  595.    Sometimes it is not possible to create an alist or an obarray
  596. containing all the intended possible completions.  In such a case,
  597. you can supply your own function to compute the completion of a given
  598. string.  This is called "programmed completion".
  599.  
  600.    To use this feature, pass the function as the ALIST-OR-OBARRAY
  601. argument to `completing-read'.  This command will arrange to pass the
  602. function along to `try-completion' and `all-completions', which will
  603. then let your function do all the work.
  604.  
  605.    The completion function should accept three arguments:
  606.  
  607.    * The string to be completed.
  608.  
  609.    * The predicate function to filter possible matches, or `nil' if
  610.      none.  Your function should call the predicale for each possible
  611.      match and ignore the possible match if the predicate returns
  612.      `nil'.
  613.  
  614.    * A flag specifying the type of operation.
  615.  
  616.    There are three flag values for three operations:
  617.  
  618.    * `nil' specifies `try-completion'.  The completion function
  619.      should return the completion of the specified string, or `t' if
  620.      the string is an exact match already, or `nil' if the string
  621.      matches no possibility.
  622.  
  623.    * `t' specifies `all-completions'.  The completion function should
  624.      return a list of all possible completions of the specified string.
  625.  
  626.    * `lambda' specifies a test for an exact match.  The completion
  627.      function should return `t' if the specified string is an exact
  628.      match for some possibility; `nil' otherwise.
  629.  
  630.    Emacs uses programmed completion when completing file names. 
  631. *Note File Name Completion::.
  632.  
  633.  
  634. 
  635. File: elisp,  Node: Minibuffer Completion,  Next: Completion Commands,  Prev: Programmed Completion,  Up: Completion
  636.  
  637. Completion and the Minibuffer
  638. -----------------------------
  639.  
  640.    This section describes the basic interface for reading from the
  641. minibuffer with completion.
  642.  
  643.  * Function: completing-read PROMPT ALIST-OR-OBARRAY &optional
  644.           PREDICATE REQUIRE-MATCH INITIAL
  645.      This function reads a string in the minibuffer, assisting the
  646.      user by providing completion.  It activates the minibuffer with
  647.      prompt PROMPT, which must be a string.  If INITIAL is non-`nil',
  648.      `completing-read' inserts it into the minibuffer as part of the
  649.      input.  Then it allows the user to edit the input, providing
  650.      several commands to attempt completion.
  651.  
  652.      The actual completion is done by passing ALIST-OR-OBARRAY and
  653.      PREDICATE to the function `try-completion'.  This happens in
  654.      certain commands bound in the local keymaps used for completion.
  655.  
  656.      If REQUIRE-MATCH is `t', the user will not be allowed to exit
  657.      unless the input completes to an element of ALIST-OR-OBARRAY. 
  658.      If REQUIRE-MATCH is neither `nil' nor `t', then
  659.      `completing-read' does not exit unless the input typed is itself
  660.      an element of ALIST-OR-OBARRAY.  To accomplish this,
  661.      `completing-read' calls `read-minibuffer' with the keymap
  662.      `minibuffer-local-completion-map' if REQUIRE-MATCH is `nil', or
  663.      else with the keymap `minibuffer-local-must-match-map', if
  664.      REQUIRE-MATCH is non-`nil'.
  665.  
  666.      Case is ignored when comparing the input against the possible
  667.      matches if the built-in variable `completion-ignore-case' is
  668.      non-`nil'.  *Note Basic Completion::.
  669.  
  670.      For example:
  671.  
  672.           (completing-read "Complete a foo: "
  673.                '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
  674.                nil t "fo")
  675.           
  676.           ;; After evaluating the preceding expression, 
  677.           ;; the following appears in the minibuffer:
  678.           
  679.           ---------- Buffer: Minibuffer ----------
  680.           Complete a foo: fo-!-
  681.           ---------- Buffer: Minibuffer ----------
  682.  
  683.      If the user then types `DEL DEL b RET', `completing-read'
  684.      returns `barfoo'.
  685.  
  686.      The `completing-read' function binds three variables to pass
  687.      information to the commands which actually do completion.  Here
  688.      they are:
  689.  
  690.     `minibuffer-completion-table'
  691.           This variable is bound to ALIST-OR-OBARRAY argument.  It is
  692.           passed to the `try-completion' function.
  693.  
  694.     `minibuffer-completion-predicate'
  695.           This variable is bound to the PREDICATE argument.  It is
  696.           passed to the `try-completion' function.
  697.  
  698.     `minibuffer-completion-confirm'
  699.           This variable is bound to the REQUIRE-MATCH argument.  It
  700.           is used in the `minibuffer-complete-and-exit' function.
  701.  
  702.  
  703. 
  704. File: elisp,  Node: Completion Commands,  Next: High-Level Completion,  Prev: Minibuffer Completion,  Up: Completion
  705.  
  706. Minibuffer Commands That Do Completion
  707. --------------------------------------
  708.  
  709.    This section describes the keymaps, commands and user options used
  710. in the minibuffer to do completion.
  711.  
  712.  * Variable: minibuffer-local-completion-map
  713.      `completing-read' uses this value as the local keymap when an
  714.      exact match of one of the completions is not required.  By
  715.      default, this keymap makes the following bindings:
  716.  
  717.     `?'
  718.           `minibuffer-completion-help'
  719.  
  720.     `SPC'
  721.           `minibuffer-complete-word'
  722.  
  723.     `TAB'
  724.           `minibuffer-complete'
  725.  
  726.     `LFD'
  727.           `exit-minibuffer'
  728.  
  729.     `RET'
  730.           `exit-minibuffer'
  731.  
  732.     `C-g'
  733.           `abort-recursive-edit'
  734.  
  735.  * Variable: minibuffer-local-must-match-map
  736.      `completing-read' uses this value as the local keymap when an
  737.      exact match of one of the completions is required.  Therefore,
  738.      no keys are bound to `exit-minibuffer', the command which exits
  739.      the minibuffer unconditionally.  By default, this keymap makes
  740.      the following bindings:
  741.  
  742.     `?'
  743.           `minibuffer-completion-help'
  744.  
  745.     `SPC'
  746.           `minibuffer-complete-word'
  747.  
  748.     `TAB'
  749.           `minibuffer-complete'
  750.  
  751.     `LFD'
  752.           `minibuffer-complete-and-exit'
  753.  
  754.     `RET'
  755.           `minibuffer-complete-and-exit'
  756.  
  757.     `C-g'
  758.           `abort-recursive-edit'
  759.  
  760.  * Variable: minibuffer-completion-table
  761.      The value of this variable is the alist or obarray used for
  762.      completion in the minibuffer.  This is the global variable that
  763.      contains what `completing-read' passes to `try-completion'.  It
  764.      is used by all the minibuffer completion functions, such as
  765.      `minibuffer-complete-word'.
  766.  
  767.  * Variable: minibuffer-completion-predicate
  768.      The value of this variable is the predicate that
  769.      `completing-read' passes to `try-completion'.  The variable is
  770.      also used by the other minibuffer completion functions.
  771.  
  772.  * Command: minibuffer-complete-word
  773.      This function completes the minibuffer contents by at most a
  774.      single word.  Even if the minibuffer contents has only one
  775.      completion, `minibuffer-complete-word' will not add any
  776.      characters beyond the first character that is not a word
  777.      constituent.  *Note Syntax Tables::.
  778.  
  779.  * Command: minibuffer-complete
  780.      This function completes the minibuffer contents as far as
  781.      possible.
  782.  
  783.  * Command: minibuffer-complete-and-exit
  784.      This function completes the minibuffer contents, and exits if
  785.      confirmation is not required, i.e., if
  786.      `minibuffer-completion-confirm' is non-`nil'.  If confirmation
  787.      *is* required, it is given by repeating this command immediately.
  788.  
  789.  * Variable: minibuffer-completion-confirm
  790.      When the value of this variable is non-`nil', Emacs asks for
  791.      confirmation of a completion before exiting the minibuffer.  The
  792.      function `minibuffer-complete-and-exit' checks the value of this
  793.      variable before it exits.
  794.  
  795.  * Command: minibuffer-completion-help
  796.      This function creates a list of the possible completions of the
  797.      current minibuffer contents.  It works by calling
  798.      `all-completions'; the values of `minibuffer-completion-table'
  799.      and `minibuffer-completion-predicate' are used as arguments. 
  800.      The list of completions is displayed as text in a buffer named
  801.      `*Completions*'.
  802.  
  803.  * Function: display-completion-list COMPLETIONS
  804.      This function displays COMPLETIONS to the stream
  805.      `standard-output' (usually a buffer).  (*Note Streams::, for
  806.      more information about streams.)  The argument COMPLETIONS is
  807.      normally a list of completions just returned by
  808.      `all-completions', but it does not have to be.  Each element may
  809.      be a symbol or a string, either of which is simply printed, or a
  810.      list of two strings, which is printed as if the strings were
  811.      concatenated.
  812.  
  813.      This function is called by `minibuffer-completion-help'.
  814.  
  815.  * User Option: completion-auto-help
  816.      If this variable is non-`nil', the completion commands
  817.      automatically display a list of possible completions whenever
  818.      nothing can be completed because the next character is not
  819.      uniquely determined.
  820.  
  821.  
  822. 
  823. File: elisp,  Node: High-Level Completion,  Next: Reading File Names,  Prev: Completion Commands,  Up: Completion
  824.  
  825. High-Level Completion  Functions
  826. --------------------------------
  827.  
  828.    This section describes the higher-level convenient functions for
  829. reading certain sorts of names with completion.
  830.  
  831.  * Function: read-buffer PROMPT &optional DEFAULT EXISTING
  832.      This function reads the name of a buffer and returns it as a
  833.      string.  The argument DEFAULT is the default name to use, the
  834.      value to return if the user exits with an empty minibuffer.  If
  835.      non-`nil', it should be a string.  It is mentioned in the
  836.      prompt, but is not inserted in the minibuffer as initial input.
  837.  
  838.      If EXISTING is non-`nil', then the name specified must be that
  839.      of an  existing buffer.  The usual commands to exit the
  840.      minibuffer will not exit if the text is not valid, and RET will
  841.      do completion to attempt to find a valid name.  (However,
  842.      DEFAULT is not checked for this; it is returned, whatever it is,
  843.      if the user exits with the minibuffer empty.)
  844.  
  845.      In the following example, the user enters `minibuffer.t', and
  846.      then types RET.  The argument EXISTING is `t', and the only
  847.      buffer name starting with the given input is `minibuffer.texi',
  848.      so that name is the value.
  849.  
  850.           (read-buffer "Buffer name? " "foo" t)
  851.           
  852.           ;; After evaluating the preceding expression, 
  853.           ;; the following prompt appears, with an empty minibuffer:
  854.           
  855.           ---------- Buffer: Minibuffer ----------
  856.           Buffer name? (default foo) -!-
  857.           ---------- Buffer: Minibuffer ----------
  858.           
  859.           ;; The user types `minibuffer.t RET'.
  860.           
  861.                => "minibuffer.texi"
  862.  
  863.  * Function: read-command PROMPT
  864.      This function reads the name of a command and returns it as a
  865.      Lisp symbol.  The argument PROMPT is used as in
  866.      `read-from-minibuffer'.  Recall that a command is anything for
  867.      which `commandp' returns `t', and a command name is a symbol for
  868.      which `commandp' returns `t'.  *Note Interactive Call::.
  869.  
  870.           (read-command "Command name? ")
  871.           
  872.           ;; After evaluating the preceding expression, 
  873.           ;; the following appears in the minibuffer:
  874.           
  875.           ---------- Buffer: Minibuffer ---------- 
  876.           Command name?  
  877.           ---------- Buffer: Minibuffer ----------
  878.  
  879.      If the user types `forward-c RET', then this function returns
  880.      `forward-char'.
  881.  
  882.      The `read-command' function is a simplified interface to
  883.      `completing-read'.  It uses the `commandp' predicate to allow
  884.      only commands to be entered, and it uses the variable `obarray'
  885.      so as to be able to complete all extant Lisp symbols:
  886.  
  887.           (read-command PROMPT)
  888.           ==
  889.           (intern (completing-read PROMPT obarray 'commandp t nil))
  890.  
  891.  * Function: read-variable PROMPT
  892.      This function reads the name of a user variable and returns it
  893.      as a symbol.
  894.  
  895.           (read-variable "Variable name? ")
  896.           
  897.           ;; After evaluating the preceding expression, 
  898.           ;; the following prompt appears with an empty minibuffer:
  899.           
  900.           ---------- Buffer: Minibuffer ----------
  901.           Variable name? -!-
  902.           ---------- Buffer: Minibuffer ----------
  903.  
  904.      If the user then types `fill-p RET', `read-variable' will return
  905.      `fill-prefix'.
  906.  
  907.      This function is similar to `read-command', but uses the
  908.      predicate `user-variable-p' instead of `commandp':
  909.  
  910.           (read-variable PROMPT)
  911.           ==
  912.           (intern (completing-read PROMPT obarray 'user-variable-p t nil))
  913.  
  914.  
  915. 
  916. File: elisp,  Node: Reading File Names,  Next: Lisp Symbol Completion,  Prev: High-Level Completion,  Up: Completion
  917.  
  918. Reading File Names
  919. ------------------
  920.  
  921.    Here is another high-level completion function, designed for
  922. reading a file name.  It provides special features including
  923. automatic insertion of the default directory.
  924.  
  925.  * Function: read-file-name PROMPT &optional DIRECTORY DEFAULT EXISTING
  926.      This function reads a file name in the minibuffer, prompting
  927.      with PROMPT and providing completion.  If DEFAULT is non-`nil',
  928.      then the value of DEFAULT will be returned by the function if
  929.      the user just types RET.
  930.  
  931.      If EXISTING is non-`nil', then the name must refer to an
  932.      existing file; then RET performs completion to make the name
  933.      valid if possible, and then refuses to exit if it is not valid. 
  934.      If the value of EXISTING is neither `nil' nor `t', then RET also
  935.      requires confirmation after completion.
  936.  
  937.      The argument DIRECTORY specifies the directory to use for
  938.      completion of relative file names.  Usually it is inserted in
  939.      the minibuffer as initial input as well.  It defaults to the
  940.      current buffer's default directory.
  941.  
  942.      Here is an example:
  943.  
  944.           (read-file-name "The file is ")
  945.           
  946.           ;; After evaluating the preceding expression, 
  947.           ;; the following appears in the minibuffer:
  948.           
  949.           ---------- Buffer: Minibuffer ----------
  950.           The file is /gp/gnu/elisp/-!-
  951.           ---------- Buffer: Minibuffer ----------
  952.  
  953.      Typing `manual TAB' results in the following:
  954.  
  955.           ---------- Buffer: Minibuffer ----------
  956.           The file is /gp/gnu/elisp/manual.texi-!-
  957.           ---------- Buffer: Minibuffer ----------
  958.  
  959.      If the user types RET, `read-file-name' returns
  960.      `"/gp/gnu/elisp/manual.texi"'.
  961.  
  962.  * User Option: insert-default-directory
  963.      This variable is used by `read-file-name'.  The value of this
  964.      variable controls whether `read-file-name' starts by placing the
  965.      name of the default directory in the minibuffer.  If the value
  966.      of this variable is `nil', then `read-file-name' does not place
  967.      any initial input in the minibuffer.  In that case, the default
  968.      directory is still used for completion of relative file names,
  969.      but is not displayed.
  970.  
  971.      For example:
  972.  
  973.           ;; Here the minibuffer starts out containing the default directory.
  974.           
  975.           (let ((insert-default-directory t))
  976.             (read-file-name "The file is "))
  977.           
  978.           ---------- Buffer: Minibuffer ----------
  979.           The file is ~lewis/manual/-!-
  980.           ---------- Buffer: Minibuffer ----------
  981.           
  982.           ;; Here the minibuffer is empty and only the prompt appears on its line.
  983.           
  984.           (let ((insert-default-directory nil))
  985.             (read-file-name "The file is "))
  986.           
  987.           ---------- Buffer: Minibuffer ----------
  988.           The file is -!-
  989.           ---------- Buffer: Minibuffer ----------
  990.  
  991.  
  992. 
  993. File: elisp,  Node: Lisp Symbol Completion,  Prev: Reading File Names,  Up: Completion
  994.  
  995. Lisp Symbol Completion
  996. ----------------------
  997.  
  998.    If you type a part of a symbol, and then type `M-TAB'
  999. (`lisp-complete-symbol'), it will attempt to fill in as much more of
  1000. the symbol name as it can.  Not only does this save typing, but it
  1001. can help you with the name of a symbol that you have partially
  1002. forgotten.
  1003.  
  1004.  * Command: lisp-complete-symbol
  1005.      This function performs completion on the symbol name preceding
  1006.      point.  The name is completed against the symbols in the global
  1007.      variable `obarray', and characters from the completion are
  1008.      inserted into the buffer, making the name longer.  If there is
  1009.      more than one completion, a list of all possible completions is
  1010.      placed in the `*Help*' buffer.  The bell rings if there is no
  1011.      possible completion in `obarray'.
  1012.  
  1013.      If an open parenthesis immediately precedes the name, only
  1014.      symbols with function definitions are considered.  (By reducing
  1015.      the number of alternatives, this may succeed in completing more
  1016.      characters.) Otherwise, symbols with either a function
  1017.      definition, a value, or at least one property are considered.
  1018.  
  1019.      `lisp-complete-symbol' returns `t' if the symbol had an exact, 
  1020.      and unique, match; otherwise, it returns `nil'.
  1021.  
  1022.      In the following example, the user has already inserted `(forwa'
  1023.      into the buffer `foo.el'.  The command `lisp-complete-symbol'
  1024.      then completes the name to `(forward-'.
  1025.  
  1026.           ---------- Buffer: foo.el ----------
  1027.           (forwa-!-
  1028.           ---------- Buffer: foo.el ----------
  1029.           
  1030.           (lisp-complete-symbol)
  1031.                => nil
  1032.           
  1033.           ---------- Buffer: foo.el ----------
  1034.           (forward--!-
  1035.           ---------- Buffer: foo.el ----------
  1036.  
  1037.  
  1038. 
  1039. File: elisp,  Node: Yes-or-No Queries,  Next: Minibuffer Misc,  Prev: Completion,  Up: Minibuffers
  1040.  
  1041. Yes-or-No Queries
  1042. =================
  1043.  
  1044.    This section describes functions used to ask the user a yes-or-no
  1045. question.  The function `y-or-n-p' can be answered with a single
  1046. character; it is useful for questions where an inadvertent wrong
  1047. answer will not have serious consequences.  `yes-or-no-p' is suitable
  1048. for more momentous questions, since it requires three or four
  1049. characters to answer.
  1050.  
  1051.    Strictly speaking, `yes-or-no-p' uses the minibuffer and
  1052. `y-or-n-p' does not; but it seems best to describe them together.
  1053.  
  1054.  * Function: y-or-n-p PROMPT
  1055.      This function asks the user a question, expecting input in the
  1056.      echo area.  It returns `t' if the user types `y', `nil' if the
  1057.      user types `n'.  This function also accepts SPC to mean yes and
  1058.      DEL to mean no.  The answer is a single character, with no RET
  1059.      needed to terminate it.  Upper and lower case are equivalent.
  1060.  
  1061.      "Asking the question" means printing PROMPT in the echo area,
  1062.      followed by the string `(y or n) '.  If the input is not one of
  1063.      the expected answers (`y', `n', `SPC', or `DEL'), the function
  1064.      responds `Please answer y or n.', and repeats the request.
  1065.  
  1066.      This function does not actually use the minibuffer, since it
  1067.      does not allow editing of the answer.  It actually uses the echo
  1068.      area (*note The Echo Area::.), which uses the same screen space
  1069.      as the minibuffer.  The cursor moves to the echo area while the
  1070.      question is being asked.
  1071.  
  1072.      In the following example, the user first types `q', which is
  1073.      invalid.  At the next prompt the user types `n'.
  1074.  
  1075.           (y-or-n-p "Do you need a lift? ")
  1076.           
  1077.           ;; After evaluating the preceding expression, 
  1078.           ;; the following prompt appears in the echo area:
  1079.  
  1080.              ---------- Echo area ----------
  1081.           Do you need a lift? (y or n) 
  1082.           ---------- Echo area ----------
  1083.  
  1084.  
  1085.                     ;; If the user then types `q', the following appears:
  1086.  
  1087.              ---------- Echo area ----------
  1088.           Please answer y or n.  Do you need a lift? (y or n) 
  1089.           ---------- Echo area ----------
  1090.  
  1091.  
  1092.                     ;; When the user types a valid answer, it is displayed after the question:
  1093.  
  1094.              ---------- Echo area ----------
  1095.           Do you need a lift? (y or n) y
  1096.           ---------- Echo area ----------
  1097.  
  1098.      Note that we show successive lines of echo area messages here. 
  1099.      Only one will appear on the screen at a time.
  1100.  
  1101.  * Function: yes-or-no-p PROMPT
  1102.      This function asks the user a question, expecting input in
  1103.      minibuffer.  It returns `t' if the user enters `yes', `nil' if
  1104.      the user types `no'.  The user must type RET to finalize the
  1105.      response.  Upper and lower case are equivalent.
  1106.  
  1107.      `yes-or-no-p' starts by displaying PROMPT in the echo area,
  1108.      followed by `(yes or no) '.  The user must type one of the
  1109.      expected responses; otherwise, the function responds `Please
  1110.      answer yes or no.', waits about two seconds and repeats the
  1111.      request.
  1112.  
  1113.      `yes-or-no-p' requires more work from the user than `y-or-n-p'
  1114.      and is appropriate for more crucial decisions.
  1115.  
  1116.      Here is an example:
  1117.  
  1118.           (yes-or-no-p "Do you really want to remove your entire directory? ")
  1119.           
  1120.           ;; After evaluating the preceding expression, 
  1121.           ;; the following prompt appears with an empty minibuffer:
  1122.           
  1123.           ---------- Buffer: minibuffer ----------
  1124.           Do you really want to remove your entire directory? (yes or no) 
  1125.           ---------- Buffer: minibuffer ----------
  1126.  
  1127.      If the user first types `y RET', which is invalid because this
  1128.      function demands the entire word `yes', it responds by
  1129.      displaying these prompts, with a brief pause between them:
  1130.  
  1131.           ---------- Buffer: minibuffer ----------
  1132.           Please answer yes or no.
  1133.           Do you really want to remove your entire directory? (yes or no)
  1134.           ---------- Buffer: minibuffer ----------
  1135.  
  1136.  
  1137. 
  1138. File: elisp,  Node: Minibuffer Misc,  Prev: Yes-or-No Queries,  Up: Minibuffers
  1139.  
  1140. Minibuffer Miscellany
  1141. =====================
  1142.  
  1143.    Some basic minibuffer functions and variables are described in
  1144. this section.
  1145.  
  1146.  * Command: exit-minibuffer
  1147.      This function exits the active minibuffer.  It is normally bound
  1148.      to keys in minibuffer local keymaps.
  1149.  
  1150.  * Command: self-insert-and-exit
  1151.      This function exits the active minibuffer after inserting the
  1152.      last character typed on the keyboard (found in
  1153.      `last-command-char'; *note Command Loop Info::.).
  1154.  
  1155.  * Variable: minibuffer-help-form
  1156.      The current value of this variable is used to rebind `help-form'
  1157.      locally inside the minibuffer (*note Help Functions::.).
  1158.  
  1159.  * Function: minibuffer-window
  1160.      This function returns the window that is used for the minibuffer.
  1161.      There is one and only one minibuffer window in Emacs 18; this
  1162.      window always exists and cannot be deleted.
  1163.  
  1164.  * Variable: minibuffer-scroll-window
  1165.      If the value of this variable is non-`nil', it should be a
  1166.      window object.  When the function `scroll-other-window' is
  1167.      called in the minibuffer, it will scroll the
  1168.      `minibuffer-scroll-window' window.
  1169.  
  1170.    Finally, some functions and variables deal with recursive
  1171. minibuffers (*note Recursive Editing::.):
  1172.  
  1173.  * Function: minibuffer-depth
  1174.      This function returns the current depth of activations of the
  1175.      minibuffer, a nonnegative integer.  If no minibuffers are
  1176.      active, it returns zero.
  1177.  
  1178.  * User Option: enable-recursive-minibuffers
  1179.      If this variable is non-`nil', you can invoke commands (such as
  1180.      `find-file') which use minibuffers even while in the minibuffer
  1181.      window.  Such invocation produces a recursive editing level for
  1182.      a new minibuffer.  The outer-level minibuffer is invisible while
  1183.      you are editing the inner one.
  1184.  
  1185.      This variable only affects invoking the minibuffer while the
  1186.      minibuffer window is selected.   If you switch windows while in
  1187.      the  minibuffer, you can always invoke minibuffer commands while
  1188.      some other window is selected.
  1189.  
  1190.  
  1191. 
  1192. File: elisp,  Node: Command Loop,  Next: Keymaps,  Prev: Minibuffers,  Up: Top
  1193.  
  1194. Command Loop
  1195. ************
  1196.  
  1197.    When you run Emacs, it enters the "editor command loop" almost
  1198. immediately.  This loop reads key sequences, executes their
  1199. definitions, and displays the results.  In this chapter, we describe
  1200. how these things are done, and the subroutines that allow Lisp
  1201. programs to do them.
  1202.  
  1203. * Menu:
  1204.  
  1205. * Command Overview::    How the command loop reads commands.
  1206. * Defining Commands::   Specifying how a function should read arguments.
  1207. * Interactive Call::    Calling a command, so that it will read arguments.
  1208. * Command Loop Info::   Variables set by the command loop for you to examine.
  1209. * Keyboard Input::      How your program can read characters from the keyboard.
  1210. * Quitting::            How `C-g' works.  How to catch or defer quitting.
  1211. * Prefix Command Arguments::    How the commands to set prefix args work.
  1212. * Recursive Editing::   Entering a recursive edit,
  1213.                           and why you usually shouldn't.
  1214. * Disabling Commands::  How the command loop handles disabled commands.
  1215. * Command History::     How the command history is set up, and how accessed.
  1216. * Keyboard Macros::     How keyboard macros are implemented.
  1217.  
  1218.  
  1219. 
  1220. File: elisp,  Node: Command Overview,  Next: Defining Commands,  Prev: Command Loop,  Up: Command Loop
  1221.  
  1222. Command Loop Overview
  1223. =====================
  1224.  
  1225.    The first thing the command loop must do is read a key sequence,
  1226. which is a sequence of characters that translates into a command.  It
  1227. does this by calling the function `read-key-sequence'.  Your Lisp
  1228. code can also call this function (*note Keyboard Input::.).  Lisp
  1229. programs can also do input at a lower level with `read-char' or
  1230. discard pending input with `discard-input'.
  1231.  
  1232.    The key sequence is translated into a command through the keymaps
  1233. of the current buffer.  *Note Keymaps::, for information on how this
  1234. is done.  The result should be a keyboard macro or an interactively
  1235. callable function.  If the key is `M-x', then it reads the name of
  1236. another command, which is used instead.  This is done by the command
  1237. `execute-extended-command' (*note Interactive Call::.).
  1238.  
  1239.    Once the command is read, it must be executed, which includes
  1240. reading arguments to be given to it.  This is done by calling
  1241. `command-execute' (*note Interactive Call::.).  For commands written
  1242. in Lisp, the `interactive' specification says how to read the
  1243. arguments.  This may use the prefix argument (*note Prefix Command
  1244. Arguments::.) or may read with prompting in the minibuffer (*note
  1245. Minibuffers::.).  For example, the command `find-file' has an
  1246. `interactive' specification which says to read a file name using the
  1247. minibuffer.  The command's function body does not use the minibuffer;
  1248. if you call this command from Lisp code as a function, you must
  1249. supply the file name string as an ordinary Lisp function argument.
  1250.  
  1251.    If the command is a string (i.e., a keyboard macro) then the
  1252. function `execute-kbd-macro' is used to execute it.  You can call
  1253. this function yourself (*note Keyboard Macros::.).
  1254.  
  1255.    If a command runs away, typing `C-g' will terminate its execution
  1256. immediately.  This is called "quitting" (*note Quitting::.).
  1257.  
  1258.  
  1259. 
  1260. File: elisp,  Node: Defining Commands,  Next: Interactive Call,  Prev: Command Overview,  Up: Command Loop
  1261.  
  1262. Defining Commands
  1263. =================
  1264.  
  1265.    A Lisp function becomes a command when its body contains, at top
  1266. level, a form which calls the special form `interactive'.  This form
  1267. does nothing when actually executed, but its presence serves as a
  1268. flag to indicate that interactive calling is permitted.  Its argument
  1269. controls the reading of arguments for an interactive call.
  1270.  
  1271. * Menu:
  1272.  
  1273. * Using Interactive::     General rules for `interactive'.
  1274. * Interactive Codes::     The standard letter-codes for reading arguments
  1275.                              in various ways.
  1276. * Interactive Examples::  Examples of how to read interactive arguments.
  1277.  
  1278.